﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using O.M.Production.Application.IService;
using O.M.Production.Domain.DTO;
using O.M.Production.ErrorCodeEnum;
using O.M.Production.Infrastuecure.IRepository;
using Public_Class_Library;

namespace O.M.Production.Write.API.Controllers
{
    /// <summary>
    /// Api控制器-内部生产
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Write_Internal_Product_Controller : ControllerBase
    {
        private readonly I_internal_product_Service _internal_product_service;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="internal_product_service"></param>
        public Write_Internal_Product_Controller(I_internal_product_Service internal_product_service)
        {
            _internal_product_service = internal_product_service;
        }

        /// <summary>
        /// 上传文件到七牛云
        /// </summary>
        /// <param name="file">文件</param>
        /// <returns>是否成功</returns>
        [HttpPost]
        public IActionResult AddFile(IFormFile file)
        {
            var res = FileHelper.UploadFile(file);
            return Ok(res);
        }
        /// <summary>
        /// 添加-内部生产
        /// </summary>
        /// <param name="product_DTO">内部生产DTO</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> Post_Add_internal_product(internal_product_DTO product_DTO)
        {
            try
            {
                var res = await _internal_product_service.Post_Add_internal_product(product_DTO);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 批量删除-内部生产
        /// </summary>
        /// <param name="product_DTO">内部生产DTO</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> Post_Batch_Del_internal_produc(List<internal_product_DTO> product_DTO)
        {
            try
            {
                var res = await _internal_product_service.Post_Batch_Del_internal_produc(product_DTO);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 修改-内部生产
        /// </summary>
        /// <param name="product_DTO">内部生产DTO</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> Post_Upd_internal_produc(internal_product_DTO product_DTO)
        {
            try
            {
                var res = _internal_product_service.Post_Upd_internal_produc(product_DTO);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
